#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x,y;
  cin>>n>>x>>y;
  string f,s,t;
  cin>>f>>s>>t;
  int k=0;
  while(t!=s){
    s+=s.substr(0,x);
    s.erase(0,x);
    for(char& x:s){
      x=f[x-'a'];
    }
    cout<<s<<endl;
    k++;
    cout<<k<<endl;
  }
  cout<<k;
}